//
//  YLAStartViewControll.swift
//  Your Lover AI
//
//  Created by 阿忠 on 2024/6/24.
//

import Foundation
import UIKit

class YLAStartViewControll: UIViewController{
    
    
    lazy var bgImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "img_launch"))
        return image
    }()
    
    lazy var logoImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "logo"))
        return image
    }()
    
    lazy var nextBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.backgroundColor = UIColor(hex: "19CC70")
        btn.setTitle("I'm 18+and Agree& contiune", for: .normal)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 25
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
        btn.addTarget(self, action: #selector(contactClick), for: .touchUpInside)
        self.view.addSubview(btn)
        return btn
    }()
    
    lazy var protocolLb: UILabel = {
        let lab = UILabel()
        let str = "By choosing to continue, you agree to the Privacy Policy and Terms , and represents that you are 18 years old"
        let attrStr = NSMutableAttributedString.init(string: str)
        lab.textColor = .white
        let privacyPolicyRange = (str as NSString).range(of: "Privacy Policy")
        attrStr.addAttribute(.foregroundColor, value: UIColor(hex: "E6AAFC"), range: privacyPolicyRange)
        let termsRange = (str as NSString).range(of: "Terms")
        attrStr.addAttribute(.foregroundColor, value: UIColor(hex: "E6AAFC"), range: termsRange)
        lab.attributedText = attrStr
        lab.font = UIFont.boldSystemFont(ofSize: 12)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        view.addSubview(lab)
        return lab
    }()
    
    lazy var protocolBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.backgroundColor = .clear
        btn.addTarget(self, action: #selector(protocolClick), for: .touchUpInside)
        self.view.addSubview(btn)
        return btn
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.red
        
        let test = GoogleMobileAdsConsentManager.shared.isPrivacyOptionsRequired
 
        setUI()
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = true
    }
    
    
    func setUI() {
        
        view.addSubview(bgImg)
        bgImg.snp.makeConstraints { make in
            make.left.top.bottom.right.equalToSuperview()
        }
        
        view.addSubview(logoImg)
        logoImg.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(206)
            make.width.height.equalTo(96)
        }
        
        nextBtn.snp.makeConstraints { make in
            make.left.equalTo(23.5)
            make.right.equalTo(-23.5)
            make.height.equalTo(52)
            make.bottom.equalTo(-129)
        }
        
        protocolLb.snp.makeConstraints { make in
            make.left.equalTo(50)
            make.right.equalTo(-50)
            make.top.equalTo(nextBtn.snp.bottom).offset(14)
        }
        
        protocolBtn.snp.makeConstraints { make in
            make.left.top.right.bottom.equalTo(protocolLb)
        }
    }
    
    @objc func contactClick() {
        print("下一步")
        let  user_set = "user_set"
        let userDefault = UserDefaults.standard
        userDefault.set(user_set, forKey: "user_set")
        let vc = YLALoadIngViewController()
        self.navigationController?.pushViewController(vc, animated: true)
       
    }
    
    @objc func protocolClick() {
        print("下一步")
        let webvc = YLAWebViewController()
        webvc.urlWeb = "https://yourloverai.xyz/yourloverai-privacy.html"
        webvc.titleWeb = "Privacy Policy"
        self.navigationController?.pushViewController(webvc, animated: true)
        
    }
   
    
}

